contentsformat: Avoid a GPtrArray
authorTimm Bäder <mail@baedert.org>
Sat, 24 Feb 2018 07:40:41 +0000 (08:40 +0100)
committerTimm Bäder <mail@baedert.org>
Sun, 25 Feb 2018 15:47:20 +0000 (16:47 +0100)
We know how many items this array will have in advance, so just malloc
enough.

gdk/gdkcontentformats.c

index cd3293f0a334b9a4e8c66a1f04900ef0f13e611f..95a8a608ae2462b93f1c05dcab63795af2826ba4 100644 (file)
@@ -147,18 +147,20 @@ GdkContentFormats *
 gdk_content_formats_new (const char **mime_types,
                          guint        n_mime_types)
 {
-  GPtrArray *array;
   guint i;
+  const char **mime_types_copy;
 
   if (n_mime_types == 0)
       return gdk_content_formats_new_take (NULL, 0, NULL, 0);
 
-  array = g_ptr_array_new ();
+  mime_types_copy = g_new (const char *, n_mime_types + 1);
+
   for (i = 0; i < n_mime_types; i++)
-    g_ptr_array_add (array, (gpointer) g_intern_string (mime_types[i]));
-  g_ptr_array_add (array, NULL);
+    mime_types_copy[i] = g_intern_string (mime_types[i]);
+
+  mime_types_copy[n_mime_types] = NULL;
 
-  return gdk_content_formats_new_take (NULL, 0, (const char **) g_ptr_array_free (array, FALSE), n_mime_types);
+  return gdk_content_formats_new_take (NULL, 0, mime_types_copy, n_mime_types);
 }
 
 /**